<?php

require_once($_SERVER['DOCUMENT_ROOT']."/jeng/jeng.php");

class AdminMenu extends JEngAuthService
{

  function procNode($nd)
  {
    $xnd=$nd->firstChild;
	$pnd=null;
	while($xnd)
	if ($xnd->nodeName=="menu")
	{
		$rm=false;
		if ($xnd->hasAttribute("right"))
			if (!$this->user()->can($xnd->getAttribute("right")))
			{
				$nd->removeChild($xnd);
				$rm=true;
				$xnd=null;
			}
		if (!$rm)
		if ($xnd->hasChildNodes())
		  $this->procNode($xnd);
		if ($xnd!=null)
		{
			$pnd=$xnd;
			$xnd=$xnd->nextSibling;
		}else{
		  if ($pnd==null)
		    $xnd=$nd->firstChild;
		  else
			$xnd=$pnd->nextSibling;
		}
	}else
		$xnd=$xnd->nextSibling;
  }

  function renderXml()
  {
    $doc=new DOMDocument();
	$doc->load($this->conf()->get("site_path")."/inc/xml/menu.xml");
	$this->procNode($doc->documentElement);
	return $doc;
  }
}

$am=new AdminMenu();
printf("%s",$am->render());

?>